home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / misc / PowerUpBuddy.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  9.0 KB  |  245 lines

  1. class classes.misc.PowerUpBuddy
  2. {
  3.    var x;
  4.    var y;
  5.    var typeArray;
  6.    var dir;
  7.    var clip;
  8.    var buddy;
  9.    var powerUpNum;
  10.    var powerUp0;
  11.    var num0;
  12.    var xMov;
  13.    var powerUp1;
  14.    var num1;
  15.    var powerUp2;
  16.    var num2;
  17.    var c = 0;
  18.    var hc1 = 0;
  19.    var hc2 = 0;
  20.    var hc3 = 0;
  21.    var hc4 = 0;
  22.    var hitCount = 0;
  23.    var ship = false;
  24.    var health = false;
  25.    var Name = "powerUpBuddy";
  26.    function PowerUpBuddy(px, py, pdir, ptypeArray)
  27.    {
  28.       this.x = px;
  29.       this.y = py;
  30.       this.typeArray = ptypeArray.slice();
  31.       if(this.typeArray[0] == "ship2" || this.typeArray[0] == "ship3" || this.typeArray[0] == "ship3B")
  32.       {
  33.          this.ship = true;
  34.       }
  35.       this.dir = pdir;
  36.       _root.d = _root.d + 1;
  37.       this.clip = _root.createEmptyMovieClip("powerUpBuddyClip",_root.d);
  38.       this.clip._x = this.x;
  39.       this.clip._y = this.y;
  40.       _root.d = _root.d + 1;
  41.       this.buddy = this.clip.attachMovie("powerUpBuddy","buddyClip",_root.d);
  42.       this.buddy.gotoAndStop(this.dir);
  43.       this.powerUpNum = this.typeArray.length / 2;
  44.       if(this.powerUpNum == 1)
  45.       {
  46.          this.buddy.chain.seg3._visible = false;
  47.          this.buddy.chain.seg2._visible = false;
  48.       }
  49.       else if(this.powerUpNum == 2)
  50.       {
  51.          this.buddy.chain.seg3._visible = false;
  52.       }
  53.       if(!this.ship)
  54.       {
  55.          var _loc3_ = 0;
  56.          var _loc5_ = this.powerUpNum;
  57.          while(_loc3_ < _loc5_)
  58.          {
  59.             _root.d = _root.d + 1;
  60.             this["powerUp" + _loc3_] = this.clip.attachMovie("powerUp","powerUp" + _loc3_,_root.d);
  61.             this["powerUp" + _loc3_]._x = this.dir != "L" ? -81 - _loc3_ * 100 : 93 + _loc3_ * 100;
  62.             this["powerUp" + _loc3_]._y = -3;
  63.             this["powerUp" + _loc3_].gotoAndStop(this.typeArray[2 * _loc3_]);
  64.             var _loc4_ = this.typeArray[2 * _loc3_];
  65.             if(_loc4_ == "doubleLaserA" || _loc4_ == "tripleLaserA" || _loc4_ == "twistLaser" || _loc4_ == "tripleTwistLaser" || _loc4_ == "rapidLaser" || _loc4_ == "bigLaser" || _loc4_ == "superLaser")
  66.             {
  67.                this["powerUp" + _loc3_].weapon = true;
  68.             }
  69.             if(_loc4_ == "lifeUp" || _loc4_ == "lifeMax")
  70.             {
  71.                this.health = true;
  72.                _root.lifeMeterClip._visible = true;
  73.             }
  74.             _root.d = _root.d + 1;
  75.             this["num" + _loc3_] = this.clip.attachMovie("buddyNum","buddyNum" + _loc3_,_root.d);
  76.             this["num" + _loc3_]._x = this.dir != "L" ? -88 - _loc3_ * 100 : 73 + _loc3_ * 100;
  77.             this["num" + _loc3_]._y = !this.ship ? -24 : -39;
  78.             this["num" + _loc3_].num = this.typeArray[1 + 2 * _loc3_];
  79.             _loc3_ = _loc3_ + 1;
  80.          }
  81.       }
  82.       else
  83.       {
  84.          _root.d = _root.d + 1;
  85.          this.powerUp0 = _root.attachMovie(this.typeArray[0],"newShipClip",_root.d + 1000);
  86.          this.powerUp0._x = this.dir != "L" ? this.clip._x - 93 : this.clip._x + 81;
  87.          this.powerUp0._y = this.clip._y - 15;
  88.          if(_root.char == "broShip1" || _root.char == "bro1")
  89.          {
  90.             this.powerUp0.gotoAndStop("bro1");
  91.          }
  92.          else
  93.          {
  94.             this.powerUp0.gotoAndStop("bro2");
  95.          }
  96.          _root.d = _root.d + 1;
  97.          this.num0 = this.clip.attachMovie("buddyNum","buddyNum" + _loc3_,_root.d);
  98.          this.num0._x = this.dir != "L" ? -88 : 63;
  99.          this.num0._y = !this.ship ? -24 : -39;
  100.          this.num0.num = this.typeArray[1];
  101.       }
  102.       this.xMov = this.dir != "R" ? -4 : 4;
  103.       _root.audio.playLevel2("powerUpBuddySlow",10);
  104.    }
  105.    function admitPowerup(which)
  106.    {
  107.       var _loc2_ = true;
  108.       if(which == "lifeUp" && _root[_root.char].life == 100)
  109.       {
  110.          _loc2_ = false;
  111.       }
  112.       if(which == "shield" && _root[_root.char].shieldOn)
  113.       {
  114.          _loc2_ = false;
  115.       }
  116.       return _loc2_;
  117.    }
  118.    function main()
  119.    {
  120.       _root.coins.alpha = 100;
  121.       if(this.health)
  122.       {
  123.          _root.lifeMeter.alpha = 100;
  124.          _root.lifeMeterClip._x = _root[_root.char].x + 6;
  125.          _root.lifeMeterClip._y = _root[_root.char].y - 12;
  126.       }
  127.       _root.c = _root.c - 1;
  128.       this.c = this.c + 1;
  129.       if(!this.ship)
  130.       {
  131.          var _loc3_ = 0;
  132.          var _loc6_ = this.powerUpNum;
  133.          while(_loc3_ < _loc6_)
  134.          {
  135.             if(this["powerUp" + _loc3_].weapon == true)
  136.             {
  137.                if(this.clip["powerUp" + _loc3_][this.typeArray[2 * _loc3_]].hitClip.hitTest(_root[_root.char + "Clip"]))
  138.                {
  139.                   if(!this.clip["powerUp" + _loc3_].hit)
  140.                   {
  141.                      if(_root.coins.num >= this.typeArray[1 + 2 * _loc3_])
  142.                      {
  143.                         _root.audio.playLevel3("weaponUpgrade",25);
  144.                         _root[_root.char].powerUp(this.typeArray[2 * _loc3_]);
  145.                         this.clip["powerUp" + _loc3_][this.typeArray[2 * _loc3_]].gotoAndPlay("hit");
  146.                         this.clip["powerUp" + _loc3_].hit = true;
  147.                         this["num" + _loc3_].num = "";
  148.                         _root.coins.addTo(-1 * this.typeArray[1 + 2 * _loc3_]);
  149.                         this.hitCount = this.hitCount + 1;
  150.                         if(this.hitCount >= this.powerUpNum)
  151.                         {
  152.                            this.xMov *= 2;
  153.                            _root.audio.playLevel2("powerUpBuddyFast",10);
  154.                         }
  155.                      }
  156.                      else
  157.                      {
  158.                         _root.coins.alpha = 130;
  159.                      }
  160.                   }
  161.                }
  162.             }
  163.             else if(this.clip["powerUp" + _loc3_].hitTest(_root[_root.char + "Clip"]))
  164.             {
  165.                if(!this.clip["powerUp" + _loc3_].hit)
  166.                {
  167.                   if(_root.coins.num >= this.typeArray[1 + 2 * _loc3_])
  168.                   {
  169.                      var _loc5_ = this.admitPowerup(this.typeArray[2 * _loc3_]);
  170.                      if(_loc5_)
  171.                      {
  172.                         var _loc4_ = this.typeArray[2 * _loc3_];
  173.                         if(_loc4_ == "doubleLaserA" || _loc4_ == "tripleLaserA" || _loc4_ == "twistLaser" || _loc4_ == "tripleTwistLaser" || _loc4_ == "bigLAser" || _loc4_ == "rapidLaser" || _loc4_ == "doubleRapidLaser")
  174.                         {
  175.                            _root.audio.playLevel3("weaponUpgrade",25);
  176.                         }
  177.                         else
  178.                         {
  179.                            _root.audio.playLevel3(_loc4_,40);
  180.                         }
  181.                         _root[_root.char].powerUp(this.typeArray[2 * _loc3_]);
  182.                         this.clip["powerUp" + _loc3_][this.typeArray[2 * _loc3_]].gotoAndPlay("hit");
  183.                         this.clip["powerUp" + _loc3_].hit = true;
  184.                         this["num" + _loc3_].num = "";
  185.                         _root.coins.addTo(-1 * this.typeArray[1 + 2 * _loc3_]);
  186.                         this.hitCount = this.hitCount + 1;
  187.                         if(this.hitCount >= this.powerUpNum)
  188.                         {
  189.                            this.xMov *= 2;
  190.                            _root.audio.playLevel2("powerUpBuddyFast",10);
  191.                         }
  192.                      }
  193.                   }
  194.                   else
  195.                   {
  196.                      _root.coins.alpha = 130;
  197.                   }
  198.                }
  199.             }
  200.             _loc3_ = _loc3_ + 1;
  201.          }
  202.       }
  203.       else if(_root.newShipClip.hitTest(_root[_root.char + "Clip"]) && _root.newShipClip._x > 150)
  204.       {
  205.          if(!_root.newShipClip.hit)
  206.          {
  207.             if(_root.coins.num >= this.typeArray[1])
  208.             {
  209.                _root.newShipClip.hit = true;
  210.                _root.shipSwitcher = new classes.misc.ShipSwitcher(this.typeArray[0],this.powerUp0._x,this.powerUp0._y);
  211.                _root.addFX("shipSwitcher");
  212.                this.num0.num = "";
  213.                _root.coins.addTo(-1 * this.typeArray[1]);
  214.                this.xMov *= 2;
  215.             }
  216.             else
  217.             {
  218.                _root.coins.alpha = 130;
  219.             }
  220.          }
  221.       }
  222.       if(this.x > 1400 || this.x < -400)
  223.       {
  224.          _root.removeFX("powerUpBuddy");
  225.       }
  226.       this.x += this.xMov;
  227.       if(!_root.newShipClip.hit)
  228.       {
  229.          this.powerUp0._y += 0.3 * Math.sin(this.hc2 += 0.2);
  230.          this.num0._y = !this.ship ? this.powerUp0._y - 21 : this.powerUp0._y - this.y - 24;
  231.       }
  232.       this.powerUp1._y += 0.3 * Math.sin(this.hc3 += 0.175);
  233.       this.num1._y = this.powerUp1._y - 21;
  234.       this.powerUp2._y += 0.3 * Math.sin(this.hc4 += 0.15);
  235.       this.num2._y = this.powerUp2._y - 21;
  236.       this.buddy._y += 0.35 * Math.sin(this.hc1 += 0.1);
  237.       this.clip._x = this.x;
  238.       this.clip._y = this.y;
  239.       if(this.ship && !_root.newShipClip.hit)
  240.       {
  241.          this.powerUp0._x += this.xMov;
  242.       }
  243.    }
  244. }
  245.